package com.duobaoyu.dby.supply.admin.controller.order;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.admin.service.AdminOrderBizService;
import com.duobaoyu.dby.supply.common.biz.dto.order.BatchCloseDTO;
import com.duobaoyu.dby.supply.common.biz.dto.order.BatchRepairDTO;
import com.duobaoyu.dby.supply.common.biz.dto.order.OrderRepairPageDTO;
import com.duobaoyu.dby.supply.common.biz.vo.order.OrderRepairDetailVO;
import com.duobaoyu.dby.supply.common.biz.vo.order.OrderRepairPageVO;
import com.pig4cloud.plugin.idempotent.annotation.Idempotent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 补单管理
 *
 * @author chenms
 * @date 2023/10/17 3:50 PM
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/order/repair")
@Api(value = "orderRepair", tags = "补单")
public class OrderRepairController {

    private final AdminOrderBizService adminOrderBizService;

    /**
     * 补单分页查询
     */
    @GetMapping("/page")
    @ApiOperation(value = "补单分页查询", notes = "补单分页查询")
    @SupplySysLog(value = "补单分页查询",operationType = OperationTypeEnum.SELECT)
    public R<Page<OrderRepairPageVO>> page(@Valid OrderRepairPageDTO orderRepairPage) {
        return R.ok(adminOrderBizService.pageOfRepair(orderRepairPage));
    }

    /**
     * 批量补单
     */
    @Idempotent(delKey = true)
    @PostMapping("/batchRepair")
    @ApiOperation(value = "批量补单", notes = "批量补单")
    @SupplySysLog(value = "批量补单",operationType = OperationTypeEnum.UPDATE)
    public R<Boolean> batchRepair(@RequestBody @Valid BatchRepairDTO batchRepair) {
        return R.ok(adminOrderBizService.batchOrderRepair(batchRepair));
    }

    /**
     * 补单明细
     */
    @Idempotent(delKey = true)
    @GetMapping("/detail/{orderSn}")
    @ApiOperation(value = "补单明细", notes = "补单明细")
    @SupplySysLog(value = "补单明细",operationType = OperationTypeEnum.SELECT)
    public R<OrderRepairDetailVO> repairDetail(@PathVariable String orderSn) {
        return R.ok(adminOrderBizService.orderRepairDetail(orderSn));
    }


    /**
     * 批量关闭
     */
    @Idempotent(delKey = true)
    @PostMapping("/batchClose")
    @ApiOperation(value = "批量关闭", notes = "批量关闭")
    @SupplySysLog(value = "批量关闭",operationType = OperationTypeEnum.UPDATE)
    public R<Boolean> batchClose(@RequestBody @Valid BatchCloseDTO batchClose) {
        return R.ok(adminOrderBizService.batchCloseOrderRepair(batchClose));
    }

}
